<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>WindowedScreen.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - Windowed Screen example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font>
<b><font color="#3A3966">If</font></b> <font color="#3A3966">InitSprite</font>() = 0 <b><font color="#3A3966">Or</font></b> <font color="#3A3966">InitKeyboard</font>() = 0 <b><font color="#3A3966">Or</font></b> <font color="#3A3966">InitMouse</font>() = 0
<font color="#3A3966">  MessageRequester</font>("Error", "Can't open the sprite system", 0)
  <b><font color="#3A3966">End</font></b>
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindow</font>(0, 0, 0, 340, 285, "Gadget and sprites!", <font color="#924B72">#PB_Window_SystemMenu</font> | <font color="#924B72">#PB_Window_SizeGadget</font> | <font color="#924B72">#PB_Window_ScreenCentered</font>)
<font color="#3A3966">  ButtonGadget</font>(1, 10,  10, 100, 25, "Grab input")
<font color="#3A3966">  ButtonGadget</font>(2, 120,  10, 100, 25, "Button 2")
<font color="#3A3966">  ButtonGadget</font>(3, 230,  10, 100, 25, "Button 3")
<font color="#3A3966">  TextGadget  </font>(4, 10, 40, 300, 30, "Press 'F1' to ungrab keyboard and mouse")

  <b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindowedScreen</font>(<font color="#3A3966">WindowID</font>(0), 10, 70, 320, 200, 0, 0, 0)
<font color="#3A3966">    LoadSprite</font>(0, <font color="#924B72">#PB_Compiler_Home</font> + "examples/sources/Data/PureBasicLogo.bmp")

    direction = 1
    playerX = 1
    playerY = 1
    
    <b><font color="#3A3966">Repeat</font></b>
      <b><font color="#3A3966">Repeat</font></b>
        <font color="#3A3966">; Always process all the events to flush the queue at every frame
</font>        Event =<font color="#3A3966"> WindowEvent</font>()
        
        <b><font color="#3A3966">Select</font></b> Event
          <b><font color="#3A3966">Case</font></b> <font color="#924B72">#PB_Event_CloseWindow</font>
            Quit = 1
        
          <b><font color="#3A3966">Case</font></b> <font color="#924B72">#PB_Event_Gadget</font>
            
            <font color="#3A3966">; Do the normal application management here
</font>            Gadget =<font color="#3A3966"> EventGadget</font>()
        
            <b><font color="#3A3966">Select</font></b> Gadget
              <b><font color="#3A3966">Case</font></b> 1
                InputReleased = 0
<font color="#3A3966">                ReleaseMouse</font>(<font color="#924B72">#False</font>)
<font color="#3A3966">                SetGadgetText</font>(4, "Press 'F1' to ungrab keyboard and mouse")
    
              <b><font color="#3A3966">Case</font></b> 2, 3
<font color="#3A3966">                SetGadgetText</font>(4, "Button "+<font color="#3A3966">Str</font>(Gadget)+" pressed.")
            <b><font color="#3A3966">EndSelect</font></b>
        
        <b><font color="#3A3966">EndSelect</font></b>
        
      <b><font color="#3A3966">Until</font></b> Event = 0 <font color="#3A3966">; Quit the event loop only when no more events are available
</font>
      <b><font color="#3A3966">If</font></b> InputReleased = 0
    
<font color="#3A3966">        ExamineMouse</font>()
    
        <font color="#3A3966">; do the sprite &amp; screen management at every frame
</font><font color="#3A3966">        ExamineKeyboard</font>()
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Up</font>)    <b><font color="#3A3966">And</font></b> playerY &gt; 0   : playerY -3 : <b><font color="#3A3966">EndIf</font></b>
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Down</font>)  <b><font color="#3A3966">And</font></b> playerY &lt; 280 : playerY +3 : <b><font color="#3A3966">EndIf</font></b>
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Left</font>)  <b><font color="#3A3966">And</font></b> playerX &gt; 0   : playerX -3 : <b><font color="#3A3966">EndIf</font></b>
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Right</font>) <b><font color="#3A3966">And</font></b> playerX &lt; 300 : playerX +3 : <b><font color="#3A3966">EndIf</font></b>
    
        <b><font color="#3A3966">If</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_F1</font>)
<font color="#3A3966">          ReleaseMouse</font>(<font color="#924B72">#True</font>)
          InputReleased = 1
        <b><font color="#3A3966">EndIf</font></b>
      <b><font color="#3A3966">EndIf</font></b>
      
      <font color="#3A3966">; Clear the screen and draw our sprites
</font><font color="#3A3966">      ClearScreen</font>(<font color="#3A3966">RGB</font>(0,0,0))
<font color="#3A3966">      ClipSprite</font>(0, 0, 0, x, x/8)
<font color="#3A3966">      DisplaySprite</font>(0, x, 100)
<font color="#3A3966">      DisplaySprite</font>(0, x, x)
<font color="#3A3966">      DisplaySprite</font>(0, 300-x, x)
<font color="#3A3966">      DisplaySprite</font>(0, playerX, playerY)
    
      x + direction
      <b><font color="#3A3966">If</font></b> x &gt; 300 : direction = -1 : <b><font color="#3A3966">EndIf</font></b>   <font color="#3A3966">; moving back to the left with negative value
</font>      <b><font color="#3A3966">If</font></b> x &lt; 0   : direction =  1 : <b><font color="#3A3966">EndIf</font></b>   <font color="#3A3966">; moving to the right with positive value
</font>        
<font color="#3A3966">      FlipBuffers</font>()       <font color="#3A3966">; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
</font>
    <b><font color="#3A3966">Until</font></b>  Quit <b><font color="#3A3966">Or</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>)
  <b><font color="#3A3966">Else</font></b>
<font color="#3A3966">    MessageRequester</font>("Error", "Can't open windowed screen!", 0)
  <b><font color="#3A3966">EndIf</font></b>
<b><font color="#3A3966">EndIf</font></b>
</font></pre>
</body></html>
